package com.gx.service.impl;

import com.gx.domain.SysLogOperation;
import com.gx.domain.SysLogOperationExample;
import com.gx.id.DefaultIdGenerator;
import com.gx.id.IdGenerator;
import com.gx.mapper.SysLogOperationMapper;
import com.gx.service.api.SysLogOperationService;
import com.gx.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysLogOperationServiceImpl implements SysLogOperationService {

    private IdGenerator idGenerator = DefaultIdGenerator.getInstance();

    @Autowired
    private SysLogOperationMapper sysLogOperationMapper;

    @Override
    public int addObject(SysLogOperation sysLogOperation) {
        sysLogOperation.setId(idGenerator.generateId());
        return sysLogOperationMapper.insert(sysLogOperation);
    }

    @Override
    public List<SysLogOperation> selectList() {
        SysLogOperationExample sysLogOperationExample = new SysLogOperationExample();
        return sysLogOperationMapper.selectByExample(sysLogOperationExample);
    }

    @Override
    public int delObject(Long id) {
        return sysLogOperationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int batchDelete(List<Long> ids) {
        SysLogOperationExample sysLogOperationExample = new SysLogOperationExample();
        SysLogOperationExample.Criteria criteria = sysLogOperationExample.createCriteria();
        criteria.andIdIn(ids);
        return sysLogOperationMapper.deleteByExample(sysLogOperationExample);
    }

    @Override
    public List<SysLogOperation> queryListLike(String creatorName, String requestUri) {
        SysLogOperationExample sysLogOperationExample = new SysLogOperationExample();
        SysLogOperationExample.Criteria criteria = sysLogOperationExample.createCriteria();
        if (StringUtils.isNotEmpty(creatorName)) {
            criteria.andCreatorNameLike("%" + creatorName + "%");
        }
        if (StringUtils.isNotEmpty(requestUri)) {
            criteria.andRequestUriLike("%" + requestUri + "%");
        }
        return sysLogOperationMapper.selectByExample(sysLogOperationExample);
    }
}
